using System;
using System.Collections;
using System.Xml;

using MediaWikiEngine.Domain;

namespace MediaWikiEngine.Command
{
	/// <summary>
	/// Summary description for Wikipage_ReplaceContent.
	/// </summary>
	public class ReplaceContent : BaseCommand
	{
		public ReplaceContent(CommandParams param, WikiConnection conn) : base(param, conn)
		{
		}

        public ReplaceContent(WikiConnection conn, WikiPage page, string content) : base(conn)
        {
            CommandParams parameters = new CommandParams();
            parameters["page"] = page;
            parameters["content"] = content;
        }

		/// <summary>
		/// Creates a Wiki Page Replace Content command using an Xml text writer.
		/// </summary>
		/// <param name="inXW"></param>
		static public void ToXml(
			XmlTextWriter inXW,
			string inPageText)
		{
			StartCommandToXml(inXW, "wikipage:replacecontent");

			StartInputToXml(inXW);
			InputNameValueToXml(inXW, "page", "$page");

			inXW.WriteStartElement("in");
			inXW.WriteAttributeString("name", "content");
			inXW.WriteString(inPageText);
			inXW.WriteEndElement();	//	/in

			EndInputToXml(inXW);

			EndCommandToXml(inXW);
		}

		public override CommandResult Execute()
		{
			WikiPage page = _params["page"] as WikiPage;
			if (null != page)
				page.WikiMarkup = _params["content"].ToString();

			return new ReplaceContentResult(new Hashtable());
		}


	}

    public class ReplaceContentResult : CommandResult
    {
        public ReplaceContentResult(Hashtable result)
            : base(result)
        {
        }

    }
}
